﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


static class EnumerableExtensionMethods
{

    public static decimal Sum<T>(this IEnumerable<T> collection)
    {
        decimal sum = 0;
        foreach (T item in collection)
        {
            sum += Convert.ToDecimal(item);
        }
        return sum;
    }

    public static decimal Product<T>(this IEnumerable<T> collection)
    {
        decimal product = 0;
        foreach (T item in collection)
        {
            product *= Convert.ToDecimal(item);
        }
        return product;
    }

    public static decimal Average<T>(this IEnumerable<T> collection)
    {
        decimal average = collection.Sum() / collection.Count();
        return average;
    }

    public static T Min<T>(this IEnumerable<T> collection) where T : IComparable<T>
    {
        if (collection.Count() == 0)
        {
            return default(T);
        }
        if (collection.Count() == 1)
        {
            return collection.First();
        }
        T min = collection.First();
        foreach (T item in collection)
        {
            if (item.CompareTo(min) < 0)
            {
                min = item;
            }
        }
        return min;
    }

    public static void Main()
    {

    }
}

